package org.example.infrastructure.persistence.fallbackFactory;

import org.example.domain.system.model.UserAccount;
import org.example.infrastructure.persistence.RemoteUserAccountPersistence;
import org.example.web.result.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class RemoteUserAccountFallbackFactory implements FallbackFactory<RemoteUserAccountPersistence> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserAccountFallbackFactory.class);

    @Override
    public RemoteUserAccountPersistence create(Throwable cause) {

        return new RemoteUserAccountPersistence() {
            @Override
            public Optional<ResultInfo<UserAccount>> getUserByUserName(String userName) {
                log.error("获取用户信息下游失败");
                return Optional.empty();
            }
        };
    }
}
